home *** CD-ROM | disk | FTP | other *** search
- /******************** ***********************/
- //
- // Player PRO 4.4x -- 669 to MADx
- //
- // Version 1.0 - 12.3.95 ANR
- //
- // To use with CodeWarrior 68K or PPC
- //
- // Antoine ROSSET
- // 16 Tranchees
- // 1206 GENEVA
- // SWITZERLAND
- //
- // FAX: (+41 22) 346 11 97
- // Compuserve: 100277,164
- // Internet: rosset@dial.eunet.ch
- //
- /******************** ***********************/
-
-
- #include "669.h"
- #include "MAD.h"
- #include "RDriver.h"
- #include "PPInOut.h"
-
- #if defined(powerc) || defined(__powerc)
- enum {
- PlayerPROPlug = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( OSType)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( Ptr*)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( MADPartition*)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( PPInfoRec*)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof( short**)))
- };
-
- ProcInfoType __procinfo = PlayerPROPlug;
- #else
- #include <A4Stuff.h>
- #endif
-
- short Tdecode16( void *msg_buf)
- {
- unsigned char *buf = msg_buf;
-
- return ( (short) buf[1] << 8) | ( (short) buf[0]);
- }
-
- void pStrcpy(register unsigned char *s1, register unsigned char *s2)
- {
- register short len, i;
-
- len = *s2;
- for ( i = 0; i <= len; i++) s1[ i] = s2[ i];
- }
-
- struct Command* GetCommand( register short PosX, register short TrackIdX, register struct MusicPattern* tempMusicPat)
- {
- if( PosX < 0) PosX = 0;
- else if( PosX >= tempMusicPat->header.PatternSize) PosX = tempMusicPat->header.PatternSize -1;
-
- return( & (tempMusicPat->Commands[ (tempMusicPat->header.PatternSize * TrackIdX) + PosX]));
- }
-
- OSErr Convert6692Mad( Ptr AlienFile, long MODSize, MADPartition *theMAD)
- {
- SixSixNine *the669 = (SixSixNine*) AlienFile;
- short i, PatMax, x, z;
- long sndSize, OffSetToSample, OldTicks, temp;
- Ptr MaxPtr;
- OSErr theErr;
- Ptr theInstrument[ 64], destPtr;
- unsigned short tempS;
- short Note, Octave;
- char *thePasByte;
-
- /**** Variables pour le MAD ****/
- struct Command *aCmd;
-
- /**** Variables pour le MOD ****/
-
- struct PatSix *PatInt;
- struct PatCmd *theCommand;
- struct SampleInfo *SInfo;
- /********************************/
-
- theMAD->header = (MADSpec*) NewPtrClear( sizeof( MADSpec));
-
- MaxPtr = (Ptr)((long) the669 + MODSize);
-
- OffSetToSample = 0x1f1L + (long) the669->NOS * 25L + (long) the669->NOP * 0x600L;
-
- for( i = 0; i < the669->NOS ; i++)
- {
- temp = (long) the669;
- temp += 0x1f1L + i*25L + 13L;
-
- SInfo = (SampleInfo*) temp;
-
- SInfo->length = Tdecode16( &SInfo->length);
- SInfo->loopStart = Tdecode16( &SInfo->loopStart);
- SInfo->loopEnd = Tdecode16( &SInfo->loopEnd);
-
- theInstrument[i] = (Ptr) ((long) the669 + (long) OffSetToSample);
- OffSetToSample += SInfo->length;
- }
-
- /******** Le 669 a été lu et analysé ***********/
- /******** Copie des informations dans le MAD ***/
-
- theMAD->header->MADIdentification = 'MADF';
- for(i=0; i<32; i++) theMAD->header->NameSignature[i] = 0;
- for(i=0; i<32; i++) theMAD->header->NameSignature[i] = the669->message[i];
-
- for(i=0; i<64; i++)
- {
- for(x=0; x<32; x++) theMAD->header->fid[i].Filename[x] = 0;
- theMAD->header->fid[i].insSize = 0;
- theMAD->header->fid[i].fineTune = 0;
- theMAD->header->fid[i].volume = 0;
- theMAD->header->fid[i].freq = 1;
- theMAD->header->fid[i].amplitude = 0;
- theMAD->header->fid[i].loopStart = 0;
- theMAD->header->fid[i].loopLenght = 0;
- }
-
- theMAD->header->PatMax = the669->NOP;
- theMAD->header->numPointers = 0;
- for(i=0; i<128; i++) theMAD->header->oPointers[ i] = the669->orderList[ i];
- theMAD->header->Tracks = 8;
-
- for(i=0; i<the669->NOS; i++)
- {
- temp = (long) the669;
- temp += 0x1f1L + i*25L + 13L;
-
- SInfo = (SampleInfo*) temp;
-
- // for( x = 0; x < 13; x++) theMAD->header->fid[i].Filename[x] = SInfo->InstruFilename[x];
- theMAD->header->fid[i].insSize = SInfo->length;
- theMAD->header->fid[i].fineTune = 0; //SInfo->fineTune;
- theMAD->header->fid[i].volume = 64; //SInfo->volume;
- theMAD->header->fid[i].freq = 1;
- theMAD->header->fid[i].amplitude = 8;
- theMAD->header->fid[i].loopStart = 0; //SInfo->loopStart;
- theMAD->header->fid[i].loopLenght = 0; //SInfo->loopEnd - SInfo->loopStart;
-
- if( theMAD->header->fid[i].insSize > 0)
- {
- theMAD->instrument[i] = NewPtr( theMAD->header->fid[i].insSize);
- BlockMove( theInstrument[i], theMAD->instrument[i], theMAD->header->fid[i].insSize);
-
- destPtr = theMAD->instrument[i];
- for( temp = 0; temp < theMAD->header->fid[i].insSize; temp++)
- {
- *(destPtr + temp) -= 0x80;
- }
- }
- else theMAD->instrument[i] = 0L;
- }
-
- for(i = the669->NOS ; i < 64; i++)
- {
- theMAD->instrument[i] = 0L;
- theMAD->header->fid[i].volume = 64;
- theMAD->header->fid[i].freq = 1;
- theMAD->header->fid[i].amplitude = 8;
- }
-
- PatInt = ( struct PatSix*) the669 + 0x1f1 + the669->NOS * 0x19;
-
- temp = (long) the669;
- temp += 0x1f1L + (long) the669->NOS * 0x19L;
-
- PatInt = ( struct PatSix*) temp;
-
- /***** TEMPORAIRE ********/
-
- theMAD->header->Tracks = 8;
- // theMAD->header->PatMax = 1;
-
- for( i = 0; i < theMAD->header->PatMax; i++)
- {
- theMAD->partition[ i] = (struct MusicPattern*) NewPtrClear( sizeof( struct MusicPattern) + theMAD->header->Tracks * 64L * sizeof( struct Command));
- theMAD->partition[ i]->header.PatternSize = 64L;
- theMAD->partition[ i]->header.CompressionMode = 'NONE';
- for( x = 0; x < 20; x++) theMAD->partition[ i]->header.PatternName[ x] = 0;
- theMAD->partition[ i]->header.PatBytes = 0L;
- theMAD->partition[ i]->header.unused2 = 0L;
-
- for( x = 0 ; x < 64; x++)
- {
- for( z = 0; z<theMAD->header->Tracks; z++)
- {
- aCmd = GetCommand( x, z, theMAD->partition[ i]);
-
- theCommand = &PatInt[ i].Cmds[ x][ z];
- thePasByte = ( Ptr) theCommand;
- if( (Ptr) theCommand >= MaxPtr) Debugger();
-
- if( thePasByte[0] == 0xFF)
- {
- aCmd->EffectCmd = 0;
- aCmd->EffectArg = 0;
- aCmd->InstrumentNo = 0;
- aCmd->AmigaPeriod = 0;
- }
- else if( thePasByte[0] == 0xFE)
- {
- aCmd->InstrumentNo = 0;
- aCmd->AmigaPeriod = 0;
- aCmd->EffectCmd = 0; // 0x0C;
- aCmd->EffectArg = 0; // theCommand->Volume;
- }
- else
- {
- aCmd->InstrumentNo = theCommand->Instru + 1;
-
- /* if( theCommand->AmigaPeriod > 0 && theCommand->AmigaPeriod < 60)
- aCmd->AmigaPeriod = theCommand->AmigaPeriod;
- else theCommand->AmigaPeriod = 0;*/
-
- aCmd->AmigaPeriod = theCommand->AmigaPeriod;
-
- Note = (aCmd->AmigaPeriod & 0xF0) >> 4;
- // Note -= 2;
- Octave = (aCmd->AmigaPeriod & 0x0F);
-
- aCmd->AmigaPeriod = Note*12 + Octave;
- }
-
- if( thePasByte[2] == 0xFF)
- {
- aCmd->EffectCmd = 0;
- aCmd->EffectArg = 0;
- }
- else
- {
- aCmd->EffectCmd = 0;
- aCmd->EffectArg = 0;
- }
- }
- }
- }
-
- return noErr;
- }
-
- OSErr Extract669Info( PPInfoRec *info, Ptr AlienFile)
- {
- SixSixNine *the669 = (SixSixNine*) AlienFile;
- long PatternSize;
- short i;
- short maxInstru;
- short tracksNo;
-
- /*** Signature ***/
-
- info->signature = '669 ';
-
- /*** Internal name ***/
-
- the669->message[ 30] = '\0';
- pStrcpy( info->internalFileName, CtoPstr( the669->message));
-
- /*** Total Patterns ***/
-
- info->totalPatterns = 0;
-
- /*** Partition Length ***/
-
- info->partitionLength = 0;
-
- /*** Total Instruments ***/
-
- info->totalInstruments = 0;
-
- pStrcpy( info->formatDescription, "\p669 Plug");
-
- return noErr;
- }
-
- OSErr Test669File( Ptr AlienFile)
- {
- SixSixNine *the669 = (SixSixNine*) AlienFile;
-
- if( the669->marker == 0x6669 || the669->marker == 0x6966) return noErr;
- else return fileNotSupportedByThisPlug;
- }
-
- OSErr main( OSType order, FSSpec *AlienFileFSSpec, MADPartition *MadFile, PPInfoRec *info, short *MADpitchTable)
- {
- OSErr myErr;
- Ptr AlienFile;
- short vRefNum, iFileRefI;
- long dirID, sndSize;
-
- #ifndef powerc
- long oldA4 = SetCurrentA4(); //this call is necessary for strings in 68k code resources
- #endif
-
- HGetVol( 0L, &vRefNum, &dirID);
- HSetVol( 0L, AlienFileFSSpec->vRefNum, AlienFileFSSpec->parID);
-
- myErr = noErr;
-
- switch( order)
- {
- case 'IMPL':
- myErr = FSOpen( AlienFileFSSpec->name, 0, &iFileRefI);
- if( myErr == noErr)
- {
- GetEOF( iFileRefI, &sndSize);
-
- // ** MEMORY Test Start
- AlienFile = NewPtr( sndSize * 2L);
- if( AlienFile == 0L) myErr = needMoreMemory;
- // ** MEMORY Test End
-
- else
- {
- DisposPtr( AlienFile);
-
- AlienFile = NewPtr( sndSize);
- myErr = FSRead( iFileRefI, &sndSize, AlienFile);
- if( myErr == noErr)
- {
- myErr = Test669File( AlienFile);
- if( myErr == noErr)
- {
- myErr = Convert6692Mad( AlienFile, GetPtrSize( AlienFile), MadFile);
- }
- }
- DisposPtr( AlienFile); AlienFile = 0L;
- }
- FSClose( iFileRefI);
- }
- break;
-
- case 'TEST':
- myErr = FSOpen( AlienFileFSSpec->name, 0, &iFileRefI);
- if( myErr == noErr)
- {
- sndSize = 1024L;
-
- AlienFile = NewPtr( sndSize);
- if( AlienFile == 0L) myErr = needMoreMemory;
- else
- {
- myErr = FSRead( iFileRefI, &sndSize, AlienFile);
- myErr = Test669File( AlienFile);
-
- DisposPtr( AlienFile); AlienFile = 0L;
- }
- FSClose( iFileRefI);
- }
- break;
-
- case 'INFO':
- myErr = FSOpen( AlienFileFSSpec->name, 0, &iFileRefI);
- if( myErr == noErr)
- {
- GetEOF( iFileRefI, &info->fileSize);
-
- sndSize = 5000L; // Read only 5000 first bytes for optimisation
-
- AlienFile = NewPtr( sndSize);
- if( AlienFile == 0L) myErr = needMoreMemory;
- else
- {
- myErr = FSRead( iFileRefI, &sndSize, AlienFile);
- if( myErr == noErr)
- {
- myErr = Extract669Info( info, AlienFile);
- }
- DisposPtr( AlienFile); AlienFile = 0L;
- }
- FSClose( iFileRefI);
- }
- break;
-
- default:
- myErr = orderNotImplemented;
- break;
- }
-
- HSetVol( 0L, vRefNum, dirID);
-
- #ifndef powerc
- SetA4( oldA4);
- #endif
- return myErr;
- }